<?php

class Model_Permissions extends Model_Abstract
{

    /**
     * 获取用户的权限
     *
     * @param int $rid
     * @param int $isObject 是获取对象还是以数组返回
     */
    public function getPermissionsByRoleId($rid,$isObject = true)
    {
        $where = array(array('role_id','and','=',$rid));
        $permissions = $this->dataList($where);
        if($isObject){
            return $permissions;
        }
        $rolePermissionsArray = array();
        $rolePermissions = $permissions->toArray();
        foreach ($rolePermissions as $rolePermission){
            $rolePermissionsArray[] = $rolePermission['res_id'];
        }
        return $rolePermissionsArray;
    }

    /**
     * 将用户的权限全部删除
     */
    public function deleteRolePermission($roleId)
    {
        $where = array('role_id=?'=>$roleId);
        return $this->getTable()->delete($where);
    }
}